
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Database {
	private Connection con;
	
	public Database(String host, String username, String password) {
		//Setup database driver
	    try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			con = DriverManager.getConnection(host,username,password);
		} catch (InstantiationException | IllegalAccessException
				| ClassNotFoundException | SQLException e) {
			e.printStackTrace();
		}
	    
	}
	
	/*
	 * Insert query into database
	 */
	public void insert(String query) {
		try {
			Statement stmt = con.createStatement();
			stmt.executeUpdate(query); 			
			stmt.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	
	/*
	 * Select query from database
	 */
	public ResultSet select(String query) {
		try {
			Statement stmt = con.createStatement();
			stmt.executeQuery(query); 
			ResultSet rs = stmt.getResultSet();
			//stmt.close();
			return rs;		
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
		
	}

}
